package com.wyh.controller.groupOne.customer;

import com.github.pagehelper.PageInfo;
import com.wyh.common.enums.ResultCodeEnum;
import com.wyh.common.result.Result;
import com.wyh.domain.vo.groupOne.customer.InvoiceheaderPageVO;
import com.wyh.domain.vo.groupOne.customer.MasterDataInvoiceheaderVO_1;
import com.wyh.service.groupOne.customer.MasterDataCInvoiceheaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "发票抬头API")
@RestController
@RequestMapping("/invoiceheader")
public class CInvoiceheaderController {

    @Autowired
    private MasterDataCInvoiceheaderService masterDataCInvoiceheaderService;

    /**
     * 根据客户id查询所有发票抬头
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "get-根据客户id查询所有发票抬头")
    @ApiImplicitParam(name = "id",value = "客户id",required = true)
    @GetMapping("selectAll/{id}")
    public Result selectAll(@PathVariable Integer id) {
        List<MasterDataInvoiceheaderVO_1> masterDataInvoiceheaderVO1List = masterDataCInvoiceheaderService.selectAll(id);
        return Result.success(masterDataInvoiceheaderVO1List);
    }

    /**
     * 添加发票抬头
     *
     * @param masterDataInvoiceheaderVO1
     * @return
     */
    @ApiOperation(value = "post-添加发票抬头")
    @PostMapping("add")
    public Result insert(@RequestBody MasterDataInvoiceheaderVO_1 masterDataInvoiceheaderVO1) {
        masterDataCInvoiceheaderService.insert(masterDataInvoiceheaderVO1);
        return Result.success();
    }

    /**
     * 更新发票抬头
     *
     * @param masterDataInvoiceheaderVO1
     * @return
     */
    @ApiOperation(value = "post-更新发票抬头")
    @PostMapping("update")
    public Result update(@RequestBody MasterDataInvoiceheaderVO_1 masterDataInvoiceheaderVO1) {
        if (masterDataInvoiceheaderVO1.getId() != null) {
            masterDataCInvoiceheaderService.update(masterDataInvoiceheaderVO1);
            return Result.success();
        }
        return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
    }

    /**
     * 更新发票抬头状态 停用-启用
     *
     * @param masterDataInvoiceheaderVO1
     * @return
     */
    @ApiOperation(value = "post-更新发票抬头状态 停用-启用")
    @PostMapping("updateStatus")
    public Result updateStatus(@RequestBody MasterDataInvoiceheaderVO_1 masterDataInvoiceheaderVO1) {
        if (masterDataInvoiceheaderVO1.getId() != null) {
            if (masterDataInvoiceheaderVO1.getStatus() != null) {
                masterDataCInvoiceheaderService.update(masterDataInvoiceheaderVO1);
                return Result.success();
            }
        }
        return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
    }

    /**
     * 删除发票抬头
     *
     * @param masterDataInvoiceheaderVO1
     * @return
     */
    @ApiOperation(value = "post-删除发票抬头")
    @PostMapping("delete")
    public Result delete(@RequestBody MasterDataInvoiceheaderVO_1 masterDataInvoiceheaderVO1) {
        if (masterDataInvoiceheaderVO1.getId() != null) {
            masterDataCInvoiceheaderService.delete(masterDataInvoiceheaderVO1);
            return Result.success();
        }
        return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "get-分页查询")
    @GetMapping("/selectPage")
    public Result selectPage(InvoiceheaderPageVO invoiceheaderVO,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        if (invoiceheaderVO.getCustomerid() != null) {
            PageInfo<MasterDataInvoiceheaderVO_1> page = masterDataCInvoiceheaderService.selectPage(invoiceheaderVO, pageNum, pageSize);
            return Result.success(page);
        }
        return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
    }

}
